import {promiseRequest } from "../../../utils/index";
import {apiBaseUrl} from "../../../utils/config";
const app = getApp();
Page({
  data: {
    rewardName:'',
    rewardCode:'',
    nickName:'',
    avatarUrl:'',
    hasReward:0,
    openid:'',
    actId:''
  },
onLoad(query) {
  //根据openid查询当前人的手机号
  let openid = query.openid;
  let actId = query.actId;
  this.data.openid=openid;
  this.data.actId=actId;
  let rewardCode = query.rewardCode;
  this.getactreceive(actId, openid, rewardCode);
},
onShow(){
},
//查询领奖人信息
getactreceive(actId, openid, rewardCode) {
  let requestObj = {
    url: '/wxa/actreceive/getRewardSure',
    method: 'post',
    dataobj: { actId: actId, openid: openid, rewardCode: rewardCode },
  };
  promiseRequest(requestObj).then((res) => {
    if (res.code == 200) {
      if (res.data) {
        this.setData({
          rewardName: res.data.rewardName,
          rewardCode: res.data.rewardCode,
          nickName: res.data.nickName,
          avatarUrl: res.data.avatarUrl,
          hasReward: res.data.hasReward
        })
      }
    }
  }).catch((errMsg) => {
  });
},
//确认兑换
sure(){
  let requestObj = {
    url: '/wxa/actreceive/sure',
    method: 'post',
    dataobj: { openid: this.data.openid, actId: this.data.actId },
  };
  promiseRequest(requestObj).then((res) => {
    if (res.code == 200) {
      if (res.data) {
        this.setData({
          hasReward: 1
        })
        wx.showToast({
          title: '兑换成功!',
          icon: 'none'
        });
      }
    }
  }).catch((errMsg) => {
  });
},
//查看更多优惠活动
moreshare() {
  wx.switchTab({
    url: '../../tabar/index/index',
  })
},
})